package com.ruoyi.qywx.callback.events;

import com.ruoyi.common.core.cache.Meta;
import com.ruoyi.qywx.callback.txl.ExtChatEncrypt;
import com.ruoyi.qywx.service.inters.SyncQiyeService;

/**
 * @author : hcl
 * @Date : 2023/9/4 14:25
 */
public class ExtChatEvent extends QywxEvent<ExtChatEncrypt> {

    public ExtChatEvent(SyncQiyeService syncService, ExtChatEncrypt encrypt, Meta meta) {
        super(syncService, encrypt, meta);
    }

    /**
     * https://developer.work.weixin.qq.com/document/path/92130#%E5%AE%A2%E6%88%B7%E7%BE%A4%E5%88%9B%E5%BB%BA%E4%BA%8B%E4%BB%B6
     */
    @Override
    public void eventExecute() {
        ExtChatEncrypt encrypt = getEncrypt();
        switch (encrypt.getChangeType()) {
            case "create":
                getSyncService().createExternalChat(getMeta(), encrypt.getChatId());
                break;
            case "update":
                getSyncService().updateExternalChat(getMeta(), encrypt);
                break;
            case "dismiss":
                getSyncService().dismissExternalChat(getMeta(), encrypt.getChatId());
                break;
        }
    }
}
